#include "historicalwatch.h"
#include "ui_historicalwatch.h"
#include<QHBoxLayout>
historicalwatch::historicalwatch(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::historicalwatch)
{
    ui->setupUi(this);
    ones.resize(12);
    hbs.resize(12);
}

historicalwatch::~historicalwatch()
{
    delete ui;
}

void historicalwatch::addhistoricalwatch(onevideoinfo *onv)
{
    onv->initUi();
    switch(num){
    case 0:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout();
            ui->w1->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 1:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w2->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 2:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w3->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 3:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w4->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 4:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w5->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 5:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w6->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 6:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w7->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 7:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w8->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 8:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w9->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 9:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w10->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 10:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w11->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    case 11:
    {
        if(!neednew)
        {
            QHBoxLayout* hb=new QHBoxLayout;
            ui->w12->setLayout(hb);
            hb->setContentsMargins(0,0,0,0);
            onv->sethistoryattribute();
            hb->addWidget(onv);
            ones[num]=onv;
            hbs[num]=hb;
        }
        else
        {
            QHBoxLayout *hb = hbs[num];
            hb->removeWidget(ones[num]);
            ones[num]->deleteLater();
            ones[num]=onv;
            hb->addWidget(onv);
        }
        break;
    }
    }
    num++;
    if(num==12)
        neednew=true;
    num%=12;
}
